<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Read from stream</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="streamwrapper.stream-open.html">« streamWrapper::stream_open</a></li>
      <li style="float: right;"><a href="streamwrapper.stream-seek.html">streamWrapper::stream_seek »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.streamwrapper.html">streamWrapper</a></li>
    <li>Read from stream</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="streamwrapper.stream-read" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">streamWrapper::stream_read</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.2, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">streamWrapper::stream_read</span> &mdash; <span class="dc-title">Read from stream</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-streamwrapper.stream-read-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>streamWrapper::stream_read</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$count</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   This method is called in response to <span class="function"><a href="function.fread.html" class="function">fread()</a></span>
   and <span class="function"><a href="function.fgets.html" class="function">fgets()</a></span>.
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Remember to update the read/write position of the stream (by the number of
    bytes that were successfully read).
   </p>
  </p></blockquote>

 </div>


 <div class="refsect1 parameters" id="refsect1-streamwrapper.stream-read-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">count</code></dt>

     <dd>

      <p class="para">
       How many bytes of data from the current position should be returned.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-streamwrapper.stream-read-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   If there are less than <code class="parameter">count</code>
   bytes available, as many as are available should be returned.
   If no more data is available, an empty string should be returned.
   To signal that reading failed, <strong><code>false</code></strong> should be returned.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-streamwrapper.stream-read-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">调用此方法失败将给出
<strong><code>E_WARNING</code></strong>（未实现）。</p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    If the return value is longer then <code class="parameter">count</code> an
    <strong><code>E_WARNING</code></strong> error will be emitted, and excess data will be
    lost.
   </p>
  </p></blockquote>
 </div>

 



 <div class="refsect1 notes" id="refsect1-streamwrapper.stream-read-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    <span class="methodname"><a href="streamwrapper.stream-eof.html" class="methodname">streamWrapper::stream_eof()</a></span> is called directly after
    calling <span class="methodname"><strong>streamWrapper::stream_read()</strong></span> to check if
    <abbr title="End Of File">EOF</abbr> has been reached. If not implemented,
    <abbr title="End Of File">EOF</abbr> is assumed.
   </p>
  </p></blockquote>
  <div class="warning"><strong class="warning">警告</strong>
    <p class="para">
      When reading the whole file (for example, with
      <span class="function"><a href="function.file-get-contents.html" class="function">file_get_contents()</a></span>), PHP will call
      <span class="methodname"><strong>streamWrapper::stream_read()</strong></span> followed by        
      <span class="methodname"><a href="streamwrapper.stream-eof.html" class="methodname">streamWrapper::stream_eof()</a></span> in a loop but as long    
      as <span class="methodname"><strong>streamWrapper::stream_read()</strong></span> returns a
      non-empty string, the return value of
      <span class="methodname"><a href="streamwrapper.stream-eof.html" class="methodname">streamWrapper::stream_eof()</a></span> is ignored.
    </p>
  </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-streamwrapper.stream-read-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.fread.html" class="function" rel="rdfs-seeAlso">fread()</a> - 读取文件（可安全用于二进制文件）</span></li>
    <li class="member"><span class="function"><a href="function.fgets.html" class="function" rel="rdfs-seeAlso">fgets()</a> - 从文件指针中读取一行</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>